Ext.define('PJ.view.registrationmanagement.AChoosedUserList', {
    extend: 'AM.default.DefaultList',
    
    alias: ['widget.signUpChoosedUserList'],
    requires: ['AM.default.jsonp.DefaultLoadJsonp'],
    title: '已选人员列表',
    
    
    queryUnitId: null,
//    height: 269,
    
    columns: [{
        header: '　　审核状态',
        dataIndex: 't.auditingState',
        width: 120,
        //sortable: false,
        renderer: function(v, meta, record){
        	meta.style="padding-bottom: 0px;padding-top: 0px;line-height: 19px;padding-left: 0px;";
            var text = "",tipText="";
            if (v == 3) {
            	tipText="待人力资源部审核";
            	text= '<div style="border-left:5px solid green;height:19px;padding-left:2px;">待人力资源部审核</div>';
            }
            else if (v == 1) {
            	text= '<div style="border-left:5px solid green;height:19px;padding-left:2px;">同意参训</div>';
            	tipText="同意参训";
            }else if (v == 2) {
            	tipText="审核未通过";
            	text= '<div style="border-left:5px solid red;height:19px;cursor: pointer;padding-left:2px;">审核未通过</div>';
            }else if (v == 4) {
            	tipText="待本单位审核";
            	text= '<div style="border-left:5px solid white;height:19px;padding-left:2px;">待本单位审核</div>';
            }else if (v == 5) {
            	tipText="本单位不同意";
            	text= '<div style="border-left:5px solid red;height:19px;padding-left:2px;">本单位不同意</div>';
            }
            meta.tdAttr = 'data-qtip="' + tipText + '" auditStatus=' + record.get("t.auditingState") + ' classUserId=' + record.get("classUserId") + ' userId=' + record.get("userId");
            return text;
        },
            listeners: {
                click: function(g, clm){
					var value = clm.getAttribute("auditStatus");
                    if (value == 2) {
                    	var win = Ext.create('PJ.view.unitregistration.AuditView', {
                            grid: g,
                            flag: false,
        					userId:clm.getAttribute("userId"),
                            title: "人员审核"
                        }).show();
                    	var actionName = "load";//默认使用非JSONP的加载方法名“load”
                        if(gj_onlineLearning_constant.loadType=="jsonp") {//根据模块的全局变量设置是否使用JSONP的方式请求数据
                        	actionName= "loadJsonp";
                        }
                        win.down('form').getForm().doAction(actionName,{//使用doAction(action,{options})；方式加载数据
                            url: g.store.perAuditUrl,
    	                    params: {
    	                    	searchClassUserId: clm.getAttribute("classUserId"),
                            	auditingType: 'shry'
    	                    },
    	                    success:function(form,action){}
                        });
                    }
                }
            }
    }, {
        header: '姓名',
        dataIndex: 't.user.userName',
        width: 90
    }/*, {
        header: '性别',
        dataIndex: 't.user.sexCode.dataName',
        width: 60
    },{
        header: '年龄',
        dataIndex: 't.user.birthday',
        width: 60
    }*/,{
        header: '所在单位',
        dataIndex: 'd.deptName',
        flex: 1,
        minWidth: 100,
        renderer: function(value, metaData, record){
            metaData.tdAttr = 'data-qtip="' + value + '"';
            return value;
        }
    }/*, {
        header: '单位及职务',
        dataIndex: 't.user.dutyRemark',
        flex: 1,
        minWidth: 100,
        renderer: function(value, metaData, record){
            metaData.tdAttr = 'data-qtip="' + value + '"';
            return value;
        }
    },{
        header: '职级',
        dataIndex: 't.user.dutyLevelCode.dataName',
        flex: 1,
        minWidth: 100,
        renderer: function(value, metaData, record){
            metaData.tdAttr = 'data-qtip="' + value + '"';
            return value;
        }
    }*/, {
        header: '学员帐号',
        dataIndex: 't.user.loginID',
        width: 80,
        renderer: function(value, metaData, record){
//            metaData.tdAttr = 'data-qtip="' + value + '"';
            return value;
        }
    }
    /*
    ,{
        header: '手机号',
        dataIndex: 't.phoneNumber',
        width: 100
    }*/
    ,{
        header: '审核时间',
        dataIndex: 't.auditingUserDate',
        width: 80,
        renderer: function(value, metaData, record){
          metaData.tdAttr = 'data-qtip="' + value + '"';
          return value;
      }
    }],
    
    initComponent: function(){
        this.store = Ext.create('PJ.' + prototype + '.registrationmanagement.AChoosedUserList');
        this.loadType = gj_onlineLearning_constant.loadType;//加载方式
        this.callParent(arguments);
    },
    
    onDeleteClick: function(button){
        var me = this;
        var records = this.getSelectionModel().getSelection();
        for(var i = 0; i<records.length;i++){
        	if (records[i].get("t.auditingState") == 1 || records[i].get("t.auditingState") == 2) {
                Ext.Msg.show({
                    title: '警告',
                    msg: '已审核的数据不能删除！',
                    icon: Ext.Msg.WARNING,
                    buttons: Ext.Msg.OK
                });
                return;
            }
        }
        Ext.Msg.confirm({
            title: '提示',
            msg: '您确定要删除这些信息吗?',
            buttons: Ext.Msg.OKCANCEL,
            fn: function(id){
                if (id == 'ok') {
                    me.loadMask.show();
                    var searchClassUserIds = new Array();
                    Ext.Array.each(records, function(name, index){
                    	searchClassUserIds.push(name.get("classUserId"));
                    });
                    var store = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
                        url: me.store.deleteUrl,
                        extraParams: { //请求的相关参数
                        	searchClassUserIds: searchClassUserIds
                        },
                        loadType:gj_onlineLearning_constant.loadType//View层的loadType调整，用来切换是否需要以JSONP方式请求。
                    });
                    store.load(function(rec, operation, success){
                    	me.loadMask.hide();
                         if (success) {//json返回结果中的success是否成功
                        	 Ext.create('AM.default.DefaultAlertBox', {
                                 title: '消息',
//                                         msg: json.msg,
                                 msg: '删除成功！',
                                 fn: function(){
                                     var store = me.getStore();
                                     store.load();
                                     me.up("window").down("signUpPreChooseUserList").getStore().load();
                                     me.up("window").grid.getStore().load();
                                     // 判断待选面板的翻页工具条是否已开启
//                                             var roleResourcePreChoisedList = me.up("window").down("roleResourcePreChoisedList");
//                                             if (roleResourcePreChoisedList.isPossibleLoad) {
//                                                 roleResourcePreChoisedList.getStore().reload();
//                                             }
                                 }
                             });
                         }else {
                        	 if (operation.error) {
                                 Ext.create('AM.default.DefaultAlertBox', {
                                     title: '消息',
                                     msg: operation.error,
                                     fn: function(){
                                         var store = me.getStore();
                                         store.load();
                                         me.up("window").down("signUpPreChooseUserList").getStore().load();
                                         me.up("window").grid.getStore().load();
                                     }
                                 });
                             }
                             else {
                                 Ext.create('AM.default.DefaultAlertBox', {
                                     title: '消息',
                                     msg: '删除失败！',
                                     fn: function(){
                                         var store = me.getStore();
                                         store.load();
                                         me.up("window").grid.getStore().load();
                                     }
                                 });
                             }
                        }
                    });
                }
                else {
                    return;
                }
            }
        });
    },
    //再次报名
    onSignupClick: function(){
        var me = this;
        var records = this.getSelectionModel().getSelection();
        for(var i = 0; i<records.length;i++){
        	if (records[i].get("t.auditingState") != 2) {
                Ext.Msg.show({
                    title: '警告',
                    msg: '只允许对审核未通过的人员进行再次报名！',
                    icon: Ext.Msg.WARNING,
                    buttons: Ext.Msg.OK
                });
                return;
            }
        }
        Ext.Msg.confirm({
            title: '提示',
            msg: '您确定要再次报名吗?',
            buttons: Ext.Msg.OKCANCEL,
            fn: function(id){
                if (id == 'ok') {
                    me.loadMask.show();
                    var searchClassUserIds = new Array();
                    Ext.Array.each(records, function(name, index){
                    	searchClassUserIds.push(name.get("classUserId"));
                    });
                    var store = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
                        url: me.store.resignUpUrl,
                        extraParams: { //请求的相关参数
                        	searchClassUserIds: searchClassUserIds
                        },
                        loadType:gj_onlineLearning_constant.loadType//View层的loadType调整，用来切换是否需要以JSONP方式请求。
                    });
                    store.load(function(rec, operation, success){
                    	me.loadMask.hide();
                         if (success) {//json返回结果中的success是否成功
                        	 Ext.create('AM.default.DefaultAlertBox', {
                                 title: '消息',
//                                         msg: json.msg,
                                 msg: '再次报名成功！',
                                 fn: function(){
                                     var store = me.getStore();
                                     store.load();
                                     me.up("window").down("signUpPreChooseUserList").getStore().load();
                                     me.up("window").grid.getStore().load();
                                     // 判断待选面板的翻页工具条是否已开启
//                                             var roleResourcePreChoisedList = me.up("window").down("roleResourcePreChoisedList");
//                                             if (roleResourcePreChoisedList.isPossibleLoad) {
//                                                 roleResourcePreChoisedList.getStore().reload();
//                                             }
                                 }
                             });
                         }else {
                        	 if (operation.error) {
                                 Ext.create('AM.default.DefaultAlertBox', {
                                     title: '消息',
                                     msg: operation.error,
                                     fn: function(){
                                         var store = me.getStore();
                                         store.load();
                                         me.up("window").down("signUpPreChooseUserList").getStore().load();
                                         me.up("window").grid.getStore().load();
                                     }
                                 });
                             }
                             else {
                                 Ext.create('AM.default.DefaultAlertBox', {
                                     title: '消息',
                                     msg: '再次报名失败！',
                                     fn: function(){
                                         var store = me.getStore();
                                         store.load();
                                         me.up("window").grid.getStore().load();
                                     }
                                 });
                             }
                        }
                    });
                }
                else {
                    return;
                }
            }
        });
    },
    listeners: {
        selectionchange: function(selModel, selected){
            this.down('#' + this.oldId + "Delete").setDisabled(selected.length === 0);
            this.down('#' + this.oldId + "Signup").setDisabled(selected.length === 0);
        },
        viewready: function(){
    		this.addDocked([{
    			dock: 'top',
    			xtype: "searchform",
    			columnCount: 2,
    			collapsedFieldSet: true,
    			fieldDefaults: {
    				labelAlign: 'right',
    				labelWidth: 100
    			},
    			items: [{
    				xtype: "textfield",
    				fieldLabel: '姓名',
    				name: "searchUserName",
    				maxLength: "10",
    				emptyText: "请输入姓名"
    			},{
    				xtype: "textfield",
    				fieldLabel: '学员帐号',
    				name: "searchLoginID",
    				maxLength: "50",
					//regex: /^[0-9]\d{0,}$/,
                    //regexText: '请输入整数！',
    				emptyText: "请输入学员帐号"
    			},{
    				xtype: "textfield",
    				fieldLabel: '所在单位',
    				name: "searchDepName",
    				maxLength: "50",
    				emptyText: "请输入所在单位"
    			}, {
                    xtype: "combo",
                    fieldLabel: '审核状态',
                    name: "auditingState",
                    store: Ext.create("Ext.data.ArrayStore", {
                        fields: ['value', 'text'],
                        data: [[1, '审核通过'], [2, '审核未通过'], [3, '未审核'],[4,'学员未审核'],[5,'学员未通过']]
                    }),
                    valueField: 'value',
                    displayField: 'text',
                    editable: false,
                    emptyText: "请选择"
                }],
    			onResetClick: function(button){
                    var form = button.up('form');
                    var gridPanel = form.grid;
                    var newParams = {
                    	searchDepId: gridPanel.queryUnitId,
                        searchClassID: gridPanel.up("window").trainingGradeId
                    };
                    gridPanel.getStore().proxy.extraParams = {};
                    
                    var params = gridPanel.getStore().proxy.extraParams;
                    Ext.apply(params, newParams);
                    
                    form.getForm().reset();
                },
    			grid: this
    		},{
    			xtype: 'toolbar',
    			dock: 'top',
    			displayInfo: true,
    			items: [this.deleteButton,'-',{
    				text: '再次报名',
    	            iconCls: 'planPersonIcon',
    	            itemId: this.oldId + "Signup",
    	            scope: this,
    	            disabled: true,
    	            handler: this.onSignupClick
    			},  "->","->",this.countSelectPanel]
    		}]);
    		// 触发权限过滤事件
    		this.fireEvent("permission", this);
    	},
    	afterrender: function(){
            this.loadMask = new Ext.LoadMask(this, {
                msg: "正在加载中,请稍后...."
            });
        }
    }
});
